def get_db_url(dbinfo):
    engine = dbinfo.get("ENGINE")
    driver = dbinfo.get("DRIVER")
    user = dbinfo.get("USER")
    password = dbinfo.get("PASSWORD")
    host = dbinfo.get("HOST")
    port = dbinfo.get("PORT")
    name = dbinfo.get("NAME")

    return "{}+{}://{}:{}@{}:{}/{}".format(engine, driver, user, password, host, port, name)


class Config:
    DEBUG = False
    TESTING = False
    # SQLALCHEMY_TRACE_MODIFICATIONS = False
    SECRECT_KEY = 'zxcvbnm'

    SQLALCHEMY_TRACK_MODIFICATIONS = True
    SQLALCHEMY_COMMIT_TEARDOWN = True


class DevelopConfig(Config):
    DEBUG = True

    dbinfo = {
        "ENGINE": "mysql",
        "DRIVER": "pymysql",
        "USER": "root",
        "PASSWORD": "zxcvbnm",
        "HOST": "localhost",
        "PORT": "3306",
        "NAME": "FlaskModel"
    }

    SQLALCHEMY_DATABASE_URI = get_db_url(dbinfo)


class TestingConfig(Config):
    DEBUG = True

    dbinfo = {
        "ENGINE": "mysql",
        "DRIVER": "pymysql",
        "USER": "root",
        "PASSWORD": "zxcvbnm",
        "HOST": "localhost",
        "PORT": "3306",
        "NAME": "FlaskModel"
    }

    SQLALCHEMY_DATABASE_URI = get_db_url(dbinfo)


class ProductConfig(Config):
    DEBUG = False

    dbinfo = {
        "ENGINE": "mysql",
        "DRIVER": "pymysql",
        "USER": "root",
        "PASSWORD": "zxcvbnm",
        "HOST": "localhost",
        "PORT": "3306",
        "NAME": "FlaskModel"
    }

    SQLALCHEMY_DATABASE_URI = get_db_url(dbinfo)


envs = {
    'develop': DevelopConfig,
    'testing': TestingConfig,
    'product': ProductConfig,
    'default': DevelopConfig,

}
